package nbcp.db.mysql

import org.slf4j.LoggerFactory
import nbcp.base.extend.*
import nbcp.base.utils.*
import nbcp.db.*
import nbcp.db.sql.*
import nbcp.db.mysql.*
import nbcp.db.mysql.entity.*
import nbcp.db.mysql.table.*


class dbr {
    companion object {
        val affectRowCount: Int
            get() = db.affectRowCount


        @JvmStatic
        val system = SystemGroup();

        @JvmStatic
        fun getGroups(): Set<IDataGroup> {
            return setOf(system)
        }

        @JvmStatic
        fun getEntity(tableName: String): SqlBaseTable<*>? {
            var groups = getGroups()

            var ret: SqlBaseTable<*>? = null
            groups.any { group ->
                ret = group.getEntities().firstOrNull { it.tableName == tableName }

                return@any ret != null
            }

            return ret;
        }

//        val event = SpringUtil.getBean<SqlEventConfig>();

//        private val execAffectRows: ThreadLocal<Int> = ThreadLocal<Int>()
//
//        fun setDbrExecAffectRows(n: Int) = execAffectRows.set(n)
//
//        @JvmStatic
//        val affectRowCount: Int
//            get() {
//                return execAffectRows.get() ?: -1
//            }
//
//
//        private val execLastAutoId: ThreadLocal<Int> = ThreadLocal<Int>()
//
//        fun setDbrExecLastAutoId(n: Int) = execLastAutoId.set(n)
//
//        @JvmStatic
//        val lastAutoId: Int
//            get() {
//                return execLastAutoId.get() ?: -1
//            }
//
//        @JvmStatic
//        internal val logger = LoggerFactory.getLogger(this::class.java.declaringClass)
//
//        @JvmStatic
//        fun getQuoteName(oriValue:String):String = "`${oriValue}`"
//
//        val converter: LinkedHashMap<SqlColumnName, IConverter> = linkedMapOf()
    }
}